﻿using System.Collections;
using System.Collections.Generic;

namespace FESSC_MESSAGE
{
    public class UserToken
    {
        private Hashtable users;

        public UserToken()
        {
            users = new Hashtable();
        }

        public void addUser(string token,string uid)
        {
            users.Add(token, uid);
        }

        public void removeUserByToken(string token)
        {
            users.Remove(token);
        }

        public void removeUserByUid(string uid)
        {
            List<string> tokens = new List<string>();
            foreach(DictionaryEntry de in users)
            {
                if (uid == de.Value as string) tokens.Add(de.Key as string);
            }
            foreach(string t in tokens)
            {
                users.Remove(t);
            }
        }

        public string getUid(string token)
        {
            return users[token] as string;
        }

        public string getToken(string uid)
        {
            foreach(DictionaryEntry de in users)
            {
                if (uid == de.Value as string) return de.Key as string;
            }
            return string.Empty;
        }

        public Hashtable getUserTokens()
        {
            return users;
        }
    }
}
